package leetcode.L500;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;

public class Ex274 {
    public int hIndex(int[] citations) {
        Arrays.sort(citations);
        int[] cita = new int[citations.length];
        for (int i = 0; i < citations.length; i++) {
            cita[citations.length-i-1] = citations[i];
        }

        int l = 0;
        int r = cita.length-1;
        while(l<r){
            int mid = l+r+1>>>1;
            if(cita[mid]>=mid+1){
                l = mid;
            }else{
                r = mid-1;
            }
        }
        return l+1;

    }

    public static void main(String[] args) {
        int[] p = {3,6,4,1,9};
        Ex274 ex274 = new Ex274();
        ex274.hIndex(p);
    }

}
